package com.example.demo;

import lombok.Data;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
public class IndexController {

    @RequestMapping("/index")
    public String index(){

        return "hello world";
    }

    /**
     * 最原始的获取参数的方式
     * @param reqeust
     * @return
     */
    @RequestMapping("/raw-name")
    public String rawParams(HttpServletRequest reqeust){
        String name = reqeust.getParameter("name");
        return "params";
    }

    @PostMapping("/name")
    public String params(@RequestParam("name") String name1){
        return "params";
    }


    @GetMapping("/name-arr")
    @ResponseBody
    public String paramsArr(
            @RequestParam String[] name,
            @RequestHeader("accept-language") String language
    ){
        return "params";
    }



    @PostMapping("/login")
    String login(@RequestBody User user){
        return "login";
    }
}


@Data
class User{
    String username;
    String password;

}
